package com.ruoyi.project.data.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.data.domain.WeightStation;
import com.ruoyi.project.data.domain.WeightStationCamera;
import com.ruoyi.project.data.mapper.WeightStationCameraMapper;
import com.ruoyi.project.data.mapper.WeightStationMapper;
import com.ruoyi.project.data.service.IWeightStationCameraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2020-03-30
 */
@Service
public class WeightStationCameraServiceImpl implements IWeightStationCameraService
{
    @Autowired
    private WeightStationCameraMapper weightStationCameraMapper;
    @Autowired
    private WeightStationMapper weightStationMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public WeightStationCamera selectWeightStationCameraById(Long id)
    {
        return weightStationCameraMapper.selectWeightStationCameraById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param weightStationCamera 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<WeightStationCamera> selectWeightStationCameraList(WeightStationCamera weightStationCamera)
    {
        return weightStationCameraMapper.selectWeightStationCameraList(weightStationCamera);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param weightStationCamera 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertWeightStationCamera(WeightStationCamera weightStationCamera)
    {
        weightStationCamera.setCreateTime(DateUtils.getNowDate());
        return weightStationCameraMapper.insertWeightStationCamera(weightStationCamera);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param weightStationCamera 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateWeightStationCamera(WeightStationCamera weightStationCamera)
    {
        weightStationCamera.setUpdateTime(DateUtils.getNowDate());
        return weightStationCameraMapper.updateWeightStationCamera(weightStationCamera);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteWeightStationCameraByIds(Long[] ids)
    {
        return weightStationCameraMapper.deleteWeightStationCameraByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteWeightStationCameraById(Long id)
    {
        return weightStationCameraMapper.deleteWeightStationCameraById(id);
    }

    @Override
    public List<WeightStation> selectStationCameraList(WeightStation weightStation) {
        List<WeightStation> list = weightStationMapper.selectWeightStationList(weightStation);
        if(list != null && list.size() > 0){
            for(WeightStation station : list){
                List<WeightStationCamera> stationCameraList = weightStationCameraMapper.selectStationCameraList2(station.getStationCode());
                if(stationCameraList != null && stationCameraList.size() > 0){
                    for(WeightStationCamera stationCamera : stationCameraList){
                        if("1".equals(stationCamera.getCameraType())){    // 进场监控
                            station.setEnterMonitor(stationCamera.getCameraStatus());
                        }else if("2".equals(stationCamera.getCameraType())){     // 出场监控
                            station.setLeaveMonitor(stationCamera.getCameraStatus());
                        }else if("3".equals(stationCamera.getCameraType())){
                            station.setWeightMonitor(stationCamera.getCameraStatus());    // 称重监控
                        }
                    }
                }
                station.setCameraList(stationCameraList);
            }
        }
        return list;
    }
}
